var MongoClient = require('mongodb').MongoClient;

var db_path = 'mongodb://47.92.111.83:27017/';
var dbs = {};
var db_connected = false;
var my_db;

MongoClient.connect('mongodb://47.92.111.83:27017/account', function(err, db) {
  if (err) {
	db_connected = false;
    throw err;
  }
  my_db = db;
  db_connected = true;
	console.log('db connect sucess!');
});

exports.connected = function()
{
	return db_connected;
}
//数据库操作都是异步的--只支持一个参数
exports.query = function(col,factor,callBack,args)
{
	if(db_connected)
	{
		my_db.collection(col).find().toArray(function(err, result)
		{
			if (err) {
			  throw err;
			}
			//console.log(result);
			callBack(result,args);
		});
	}
	else
	{
		callBack(false);
	}
} 